package com.kiki.searchlog.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.kiki.common.annotation.Log;
import com.kiki.common.core.controller.BaseController;
import com.kiki.common.core.domain.AjaxResult;
import com.kiki.common.enums.BusinessType;
import com.kiki.searchlog.domain.Searchlog;
import com.kiki.searchlog.service.ISearchlogService;
import com.kiki.common.utils.poi.ExcelUtil;
import com.kiki.common.core.page.TableDataInfo;

/**
 * 搜索结果日志Controller
 * 
 * @author 林志毅
 * @date 2025-02-19
 */
@RestController
@RequestMapping("/searchlog/searchlog")
public class SearchlogController extends BaseController
{
    @Autowired
    private ISearchlogService searchlogService;

    /**
     * 查询搜索结果日志列表
     */
    @PreAuthorize("@ss.hasPermi('searchlog:searchlog:list')")
    @GetMapping("/list")
    public TableDataInfo list(Searchlog searchlog)
    {
        startPage();
        List<Searchlog> list = searchlogService.selectSearchlogList(searchlog);
        return getDataTable(list);
    }

    /**
     * 导出搜索结果日志列表
     */
    @PreAuthorize("@ss.hasPermi('searchlog:searchlog:export')")
    @Log(title = "搜索结果日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Searchlog searchlog)
    {
        List<Searchlog> list = searchlogService.selectSearchlogList(searchlog);
        ExcelUtil<Searchlog> util = new ExcelUtil<Searchlog>(Searchlog.class);
        util.exportExcel(response, list, "搜索结果日志数据");
    }

    /**
     * 获取搜索结果日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('searchlog:searchlog:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId)
    {
        return success(searchlogService.selectSearchlogByLogId(logId));
    }

    /**
     * 新增搜索结果日志
     */
    @PreAuthorize("@ss.hasPermi('searchlog:searchlog:add')")
    @Log(title = "搜索结果日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Searchlog searchlog)
    {
        return toAjax(searchlogService.insertSearchlog(searchlog));
    }

    /**
     * 修改搜索结果日志
     */
    @PreAuthorize("@ss.hasPermi('searchlog:searchlog:edit')")
    @Log(title = "搜索结果日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Searchlog searchlog)
    {
        return toAjax(searchlogService.updateSearchlog(searchlog));
    }

    /**
     * 删除搜索结果日志
     */
    @PreAuthorize("@ss.hasPermi('searchlog:searchlog:remove')")
    @Log(title = "搜索结果日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds)
    {
        return toAjax(searchlogService.deleteSearchlogByLogIds(logIds));
    }
}
